unit dgAddPad ;

interface

uses
   Windows,
   Messages,
   SysUtils,
   Variants,
   Classes,
   Graphics,
   Controls,
   Forms,
   Dialogs,
   StdCtrls,
   TntStdCtrls,
   SpTBXEditors,
   SpTBXControls,
   TBXDkPanels,
   uBasic,
   uObjects,
   GDIPOBJ,
   GDIPAPI ;

type
   TdlgAddPad = class( TForm )
      SpTBXPanel1 : TSpTBXPanel ;
      btnOK : TSpTBXButton ;
      btnCancel : TSpTBXButton ;
      SpTBXGroupBox5 : TSpTBXGroupBox ;
      seSizeX : TSpTBXSpinEdit ;
      seSizeY : TSpTBXSpinEdit ;
      rgType : TSpTBXRadioGroup ;
      rgOrient : TSpTBXRadioGroup ;
      rgLayer : TSpTBXRadioGroup ;
    SpTBXButton1: TSpTBXButton;
      procedure btnOKClick( Sender : TObject ) ;
   private
      fPad : TMedaPad ;
      procedure SetPad( const Value : TMedaPad ) ;
   public
      property Pad : TMedaPad read fPad write SetPad ;
   end ;

implementation

{$R *.dfm}

uses
  uViewPCB ;

{ TMedaObjectDialog }

procedure TdlgAddPad.btnOKClick( Sender : TObject ) ;
var
   iTrans           : TMedaTransform ;
   iLayer           : TMedaLayerType ;
begin
   iTrans := fPad.Transforms[ 0 ] ;
   if assigned( fPad ) then begin
      fPad.PadType := TMedaPadType( rgType.ItemIndex + 1 ) ;
      fPad.Size := MakeSize( seSizeX.Value, seSizeY.Value ) ;
      if rgOrient.ItemIndex < 4 then
         iTrans.Rotation := 45 * rgOrient.ItemIndex
      else if rgOrient.ItemIndex > 4 then
         iTrans.Rotation := 45 * ( rgOrient.ItemIndex - 1 ) ;
      fPad.Transforms[ 0 ] := iTrans ;
      iLayer := TMedalayerType( rgLayer.ItemIndex + 2 ) ;
      if iLayer <> fPad.Layer  then  begin
        fPad.Unplace ;
        fPad.PlaceRef := vsbPCBViewer.Layers[ iLayer ].ID ;
        fPad.PlaceMe ;
      end;
   end ;
end ;

procedure TdlgAddPad.SetPad( const Value : TMedaPad ) ;
begin
   fPad := Value ;
   if assigned( fPad ) then begin
      rgLayer.ItemIndex := integer( fPad.Layer ) - 2 ;
      rgType.ItemIndex := integer( fPad.PadType ) - 1 ;
      seSizeX.Value := fPad.Size.Width ;
      seSizeY.Value := fPad.Size.Height ;
      if integer( fPad.Transforms[ 0 ].Rotation ) < 4 then
         rgOrient.ItemIndex := integer( fPad.Transforms[ 0 ].Rotation )
      else
         rgOrient.ItemIndex := integer( fPad.Transforms[ 0 ].Rotation ) + 1 ;
   end ;
end ;

end.

